<?php

/**
 * @author Terry & 千里孤坟
 * @copyright 2009
 */
 
	error_reporting(2);
	require_once("status_class.php");
 
/**
 * All Basic Class defined here.
 */
 
/**
* 角色
*/
class Char {
	var $cid;			//数据库编号
	var $name;
	var $group;			//组别
	
	var $done;			//本回合是否已行动过

	var $mxhp;
	var $hp;
	var $mxsp;
	var $sp;
	var $mxtp;
	var $tp;
		
	var $str;
	var $mgr;
	var $spd;
	var $vit;
	var $luk;
	
	var $element;		//属性0无 1火 2冰 3雷 4地 5风 6光 7暗
	var $gender;		//0女 1男
	var $baselv;		//基础等级
	
	var $before_status;		//事前状态数组，如耐下降，全能力上升
	var $atkskill_status;	//攻击方技能影响数组，如命中率上升
	var $defskill_status;	//防御方技能影响数组，如回避率上升
	var $atkafter_status;	//攻击方事后状态数组, 如X的眼光
	var $defafter_status;	//防御方事后状态数组，如不屈
	var $eventskill_status;	//技能进行中事件数组，如毒防御，胜利的熊叫	
	
	var $res;			//耐性数组，具体见前台页面			

	//深度克隆方法
	function __clone() { 
		Action::clone_chars($this->before_status,&$this->before_status);
		Action::clone_chars($this->atkskill_status,&$this->atkskill_status);
		Action::clone_chars($this->defskill_status,&$this->defskill_status);
		Action::clone_chars($this->atkafter_status,&$this->atkafter_status);
		Action::clone_chars($this->defafter_status,&$this->defafter_status);
		Action::clone_chars($this->eventskill_status,&$this->eventskill_status);	
		Action::clone_chars($this->turnskill_status,&$this->turnskill_status);	
	} 

	public function __construct() {
		$this->forceaction = 0;
		$this->done = 0;
		$this->isdummy = 0;
		$this->before_status = array(
										0 => new Up,
										1 => new ShunJianHuiFu,
										2 => new UnDef,
										3 => new StrUp20,
										4 => new StrDown20,
										5 => new MgrUp20,
										6 => new MgrDown20,
										7 => new SpdUp20,
										8 => new SpdDown20,
										9 => new VitUp20,
										10 => new VitDown20,
										11 => new AllUp20,
										12 => new AllDown20,
										13 => new AllUp30,
										14 => new StrUp30,
										15 => new MgrUp30,
										16 => new SpdUp30,
										17 => new Rouse, //觉醒
//										18 => new BodUp, //观世音济度专用
										19 => new AllUp50,
//常规异常，从20-29
										20 => new Poison,
										21 => new Weak,
										22 => new Close,
										23 => new Paralysis,
										24 => new Old,
										25 => new High,
										26 => new Lure,
										27 => new Terror,
										28 => new Confuse,
										29 => new Curse,
//五元素打消和五元素墙壁，从30-39
										30 => new FireResZero,
										31 => new IceResZero,
										32 => new WindResZero,
										33 => new ThunderResZero,
										34 => new EarthResZero,
										35 => new FireDef,
										36 => new IceDef,
										37 => new ThunderDef,
										38 => new WindDef,
										39 => new EarthDef,
										40 => new StarGate, 	//星之门
										41 => new StopAction,
										42 => new BoreSkirt, //蜃気楼
										43 => new SDayBefore,	//圣母院和凡尔赛宫
										44 => new AxiomShield, //摂理の盾
										45 => new IncAvoid10, //小检查
										46 => new IncAvoid20, //大检查
										47 => new SaintGuard, //聖者の歌
										48 => new AllUp25, //恒河水
										49 => new KuDown30, //苦辛
										50 => new SkyE, //天の鼓動
										51 => new AllUp5,
										52 => new CrtUp, //会心的预言
										53 => new ClothDown, //汝の衣は無力なり
										54 => new NightA, //夜のオーロラ
										55 => new DevilU, //魔界の調べ
										56 => new NoWeakPoint, //弱点打消
										57 => new NTime, //ノルンの瞬き
										58 => new RedC, //赤のカポーテ
										59 => new CWind, //極彩の疾風
										60 => new Leary, //猜疑
										61 => new GMalice, //神の悪意
										62 => new AutoHPCure1,
										63 => new AutoHPCure2,
										64 => new AutoHPCure3,
										65 => new AutoSPCure1,
										66 => new AutoSPCure2,
										67 => new AutoSPCure3,
										68 => new MgrUp15,
										69 => new StrUp15,
//										70 => new AutoTPCure3,
										71 => new AllResTurn,
//										72 => new TrueAllResTurn,
										73 => new NoLuk,
										74 => new StrUp60,
										75 => new MPrison,	//ミラープリズン
										76 => new AllDown30,
										77 => new LukDown20,
										78 => new OpenEye, //黒い神の開目
										79 => new ChaosF, //迷雾
										80 => new Stone, //石化
										81 => new AllResZero, //耐性全打消
										82 => new OPrayBuff, //奥尔良的祈祷
										83 => new VitUp30, //常规耐上升30
										84 => new StrUp5,
										85 => new MgrUp5,
										86 => new VitUp5,
										87 => new SpdUp5,
										88 => new FireResKill,
										89 => new IceResKill,
										90 => new WindResKill,
										91 => new ThunderResKill,
										92 => new EarthResKill,
										93 => new LightDef,
										94 => new DarkDef,
										95 => new MoonQ,
										96 => new NightQ,
										97 => new BodR,
										98 => new DragonS,
									);
		$this->atkskill_status = array(
										0 => new AtkAfterStatus,
										1 => new BasuteBooster,
										2 => new AllCrtUp15,
										3 => new AllCrtUp30,
										4 => new PhyCharge,
										5 => new MgrCharge,
										6 => new Rousing, //觉醒中
										7 => new Backfire,	  //攻击反噬
										8 => new Purka,	  //破见切枪
										9 => new DCharge,
//										10 => new MoonQ,	  //满月女王
										11 => new MagicEnhanced,	  //魔法スキル強化
										12 => new Olding,	//老化中
										13 => new EdenDrug,	  //天の配剤
										14 => new CrtPrediction,	  //会心的预言
										15 => new GodAttack,
										16 => new Buste,	  //ブースタ
										17 => new HiBuste,	  //ハイブースタ
										18 => new Destroyer,	  //破壊神のゆえつ
										19 => new SunCrt,	  //煌天の会心
										20 => new SilentCrt,	  //静天の会心
										21 => new ColorfulW,	  //極彩の疾風
										22 => new SkillMastery,	//武道の心得
										23 => new MagicMastery,	//魔術の素養
										24 => new Weapon,	//破耐性枪
										25 => new Longki,	//ロンギヌス
										26 => new MirrorP, //水镜炼狱
										27 => new PhyBuste, 
										28 => new PhyHiBuste, 
										29 => new SDayAtkSkill, //多个特殊地形前置处理
										30 => new NoCost, //多个特殊地形前置处理
										31 => new ExFireResKill,
										32 => new ExIceResKill,
										33 => new ExWindResKill,
										34 => new ExThunderResKill,
										35 => new ExEarthResKill,
										36 => new BeCommanded,
										37 => new OmniWeapon,
										38 => new ThruWeapon,
										39 => new BreathWeapon,
										40 => new FireWeapon,
										41 => new IceWeapon,
										42 => new EleWeapon,
										43 => new OracleStone,
										44 => new EleAllAttack,
										45 => new LightWeapon,
										46 => new DarkWeapon,
										47 => new ZionSpear,
										48 => new CriticalMaster,	//会心激化
										49 => new NornsReverse,	//天命反转
										50 => new CriticalBuff,	//会心
										51 => new OpenEyed, //黒い神の開目
										52 => new HellS, //異界の住人
										53 => new HamaBuste, //観世音の済度用
										54 => new MutoBuste, //極·龍脈の秘術
										55 => new NorEleWeapon,
									);
		$this->defskill_status = array(
										0 => new Down,
										1 => new FlowerArray,
										2 => new AbnormalHitUp15For5,
										3 => new Def,
										4 => new AvoidUp10,
										5 => new AvoidUp20,
										6 => new AllSptGuard,
										7 => new DefShield,	//護りの盾
										8 => new BlackD,	//黑裙子
										9 => new GoddnessShield,	//女神の大盾
										10 => new ChaosFogDef,	//迷雾
//										11 => new DarkQ,	//夜之女王
										12 => new ArchAngelProtect,	//大天使の加護
										13 => new SoRing,	//ソロモンの指輪
										14 => new ColorW,	//極彩の疾風
										15 => new Counter,	
										16 => new HeavyCounter,	
										17 => new HyperCounter,	
										18 => new DeathCounter,	
										19 => new LordProtect,	//大魔王の加護	
										20 => new Jink,	
										21 => new TrueJink,
										22 => new FlyAway,
										23 => new PhyM,	//物反镜
										24 => new MgrM,	//魔反镜
										25 => new AriS, //觉醒
										26 => new Blocked, //被替挡，一次性
										27 => new Blocker, //替挡人，一次性
										29 => new SEncourage, //天之鼓动
										30 => new HeartEye, //心眼
										31 => new ChaosUndulate, //混沌の波動
										32 => new RCloak, //赤のカポーテ
									);
		$this->atkafter_status = array(
										0 => new AtkAfterStatus,
										1 => new BeastEye,
										2 => new DragonEye,
										3 => new CharmAfter,	//魅惑后续
										4 => new HellStayer,	  //異界の住人
										5 => new NormalVF,	//普通勝利の戦火
										6 => new Uragiri,
										7 => new TeaseTurn,	//恶戏时间经过状态
										8 => new BeCharmed,	
										9 => new BeCrawled,	
										10 => new BeCharmedInDuel,	
										11 => new BossAgain,	
										12 => new DClaim, //死亡宣告	
									);
		$this->defafter_status = array(
										0 => new DefAfterStatus,
										2 => new UnlimitedCircle, //ウロボロスの環
										1 => new Gnash, //硬食
										3 => new RouseAfter, //觉醒后
										4 => new Arise, //不屈
										5 => new DragonReverseScale, //竜神の逆鱗
//										8 => new SDayDefafter, //特殊地形
//										9 => new DropChest, //BOSS宝箱
									);
		$this->eventskill_status = array(
										0 => new EventSkillStatus,
										1 => new ShouriNoXichui,
										2 => new ShouriNoShout,
										3 => new OnceDance, //瞬転の舞踏
										4 => new Mistilteinn, //破防道具
										5 => new Alive, //生還
										6 => new ZionAlive, //大生還
										7 => new PoisonGuard,
										8 => new OldGuard,
										9 => new CloseGuard,
										10 => new PalaGuard,
										11 => new QuickRecover,
										12 => new BodyGuard,
										13 => new HighGuard,
										14 => new LureGuard,
										15 => new TerrorGuard,
										16 => new ConfuseGuard,
										17 => new EscapeSpeedUp,
										18 => new MetalGuard,
										19 => new ChaosBeam,
										20 => new GangesS,
										21 => new AllRes,
										22 => new TrueAllRes,
										23 => new DeathRes, //即死攻击免疫一次
										24 => new RonWeapon, //ロンゴミアント
										25 => new HellMask,
									);
		$this->turnskill_status = array(
										0 => new BadAirTurn,
										1 => new GuardStarsTurn,
										2 => new CrtUp15Turn,
										3 => new CrtUp30Turn,
										4 => new SBargainTurn,
										5 => new Escaped,
									);
		 
		$this->res = array(0,0,0,0,0,0,0,0,0);	

	}
	
} 

/** 不利状态ID数组 **/
$g_bad_status = array(4,6,8,10,12,77);
/** 有利状态ID数组 **/
$g_good_status = array(3,5,7,9,11,13,14,15,16,19,74,83,84,85,86,87,68,69);
/** 肉体异常数组 **/
$g_body_spt = array(20,22,23,24);
/** 精神异常数组 **/
$g_mental_spt = array(25,26,27,28);
/** 所有异常数组 **/
$g_all_spt = array_merge($g_body_spt,$g_mental_spt);

/**
 * 行动状态记录类，嘿嘿嘿
 */
Class Action {
	
	public function __construct($turn,$a,$b,$terr,$r,$s,$ei) {
		$this->turn = $turn;
		$this->a = $a;
		$this->b = $b;
		$this->terr = $terr;
		$this->result = $r;
		$this->show = $s;
		$this->extrainfo = $ei;
	}
	
	/**
 	* Clone整个对象数组$a到$b 	 
 	*/
	public static function clone_chars($a,$b) {
		//$b = array();
		for($i=0;$i<count($a);$i++) {
			if(!is_object($a[$i])) {
				continue;
			}
			$b[$i] = clone $a[$i];
		}
		//return $b;
	}  

	/**
	* 备份状态
	*/
	public static function save() {
		$am = null;
 		$bm = null;
		Action::clone_chars($_SESSION['a'],&$am);
		Action::clone_chars($_SESSION['b'],&$bm);
 		$_SESSION['save'][count($_SESSION['save'])] = new Action($_SESSION['turn'],$am,$bm,$_SESSION['T'],$_SESSION['result'],$_SESSION['show'],$_SESSION['extrainfo']);
		$keeps = 5;
		if(count($_SESSION['save']) > $keeps) {
			$_SESSION['save'][count($_SESSION['save'])-($keeps+1)] = "";
		}
	}
	
	/**
	* 恢复状态
	*/
	public static function load() {
		if(count($_SESSION['save']) == 0) {
			$_SESSION['result'] .= "已恢复到最初状态！<br>";
			return;
		}
		if(($_SESSION['save'][count($_SESSION['save'])-1]) == "") {
			$_SESSION['result'] .= "已达到回退次数上限<br>";
			return;
		}
		$tmp = $_SESSION['save'][count($_SESSION['save'])-1];
		$am = null;
 		$bm = null;
 		$a = $tmp->a;
 		$b = $tmp->b;
		Action::clone_chars($a,&$am);
		Action::clone_chars($b,&$bm);
		$_SESSION['turn'] = $tmp->turn;
		$_SESSION['a'] = $am;
		$_SESSION['b'] = $bm;
		$_SESSION['T'] = $tmp->terr;
		$_SESSION['result'] = $tmp->result;
		$_SESSION['extrainfo'] = $tmp->extrainfo;
		$_SESSION['show'] = $tmp->show;
		unset($_SESSION['save'][count($_SESSION['save'])-1]);		
	} 
}


?>
